//
//  MatchMachineTableViewCell.m
//  SmartCup
//
//  Created by Kendama on 2017/5/23.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "MatchMachineTableViewCell.h"
@interface MatchMachineTableViewCell ()
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *numberLabel;
/** 连接按钮 **/
@property(nonatomic,strong) UIButton *connectButton;

@end

@implementation MatchMachineTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self masLayout];
    }
    return self;
}

- (void) masLayout {
    __weak UIView *superView = self;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.mas_equalTo(px1080Width(48));
        make.width.mas_equalTo(px1080Width(256));
        make.height.mas_equalTo(px1920Height(60));
    }];
    
    [self.connectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right).with.offset(-px1080Width(38));
        make.width.mas_equalTo(px1080Width(132));
        make.height.mas_equalTo(px1920Height(76));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(superView);
        make.left.equalTo(self.iconImageView.mas_right).with.offset(px1080Width(46));
        make.right.equalTo(self.connectButton.mas_left).with.offset(-px1080Width(46));
        make.height.mas_equalTo(px1920Height(100));
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(superView);
        make.left.equalTo(self.iconImageView.mas_right).with.offset(px1080Width(46));
        make.right.equalTo(self.connectButton.mas_left).with.offset(-px1080Width(46));
        make.height.mas_equalTo(px1920Height(100));
    }];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"MatchMachineTableViewCell";
    id cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (void)setDevice:(DTCDeviceModel *)device {
   _device = device;
    _nameLabel.text = [NSString stringWithFormat:@"产品名称：%@",device.localName];
    _numberLabel.text = [NSString stringWithFormat:@"设备序列号：%@",device.mac];
}

- (void) didClickConnectButton {
    if (self.matchBlock) {
        self.matchBlock();
    }
}

#pragma mark -- 懒加载 
- (UILabel *)nameLabel
{
    if(!_nameLabel)
    {
        UIView *superView = self;
        _nameLabel = [[UILabel alloc]init];
        [superView addSubview:_nameLabel];
        [_nameLabel setFont:[UIFont systemFontOfSize:px1080Width(36)]];
        [_nameLabel setTextColor:[UIColor colorWithHexString:@"#585D6D"]];
        _nameLabel.text = @"产品名称：【一杯子】";
    }
    return _nameLabel;
}
- (UILabel *)numberLabel
{
    if(!_numberLabel)
    {
        UIView *superView = self;
        _numberLabel = [[UILabel alloc]init];
        [superView addSubview:_numberLabel];
        [_numberLabel setFont:[UIFont systemFontOfSize:px1080Width(36)]];
        [_numberLabel setTextColor:[UIColor colorWithHexString:@"#585D6D"]];
        _numberLabel.text = @"设备序列号：07551314521";
    }
    return _numberLabel;
}

- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        UIView *superView = self;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
        _iconImageView.image = [UIImage imageNamed:@"home_logo"];
    }
    return _iconImageView;
}

//
- (UIButton *)connectButton
{
    if(!_connectButton)
    {
        UIView *superView = self;
        _connectButton = [[UIButton alloc]init];
        [superView addSubview:_connectButton];
        [_connectButton setTitle:@"连接" forState:UIControlStateNormal];
        [_connectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_connectButton setBackgroundImage:[UIImage imageNamed:@"button_login_nor"] forState:UIControlStateNormal];
        [_connectButton.titleLabel setFont:[UIFont systemFontOfSize:px1080Width(36)]];
        [_connectButton addTarget:self action:@selector(didClickConnectButton) forControlEvents:UIControlEventTouchUpInside];

    }
    return _connectButton;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
